package com.weng.platform.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.platform.entity.Project;
import com.weng.platform.platform.mapper.ProjectMapper;
import com.weng.platform.platform.service.IProjectService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;


/**
 * 平台项目 服务实现类
 *
 * @author weng
 * @date 2021-01-15 17:18:40
 *
 */ 
@Slf4j
@Service
public class ProjectServiceImpl extends BaseServiceImpl<ProjectMapper, Project> implements IProjectService {
	@Autowired
	private ProjectMapper projectMapper;
	

	/**
	 * 分页查询平台项目
	 * @return
	 */
	@Override
	public IPage<Project> list(Integer pageNo,Integer pageSize, String ownerId, String name, String type) {
		QueryWrapper<Project> qw = new QueryWrapper<>();
		type = StringUtils.isEmpty(type) ? "-1" : type;
		qw.eq("owner_id", ownerId);
		qw.eq("type", type);
		if(StringUtils.isNotEmpty(name)){
			qw.like("name", name + "%");
		}
		qw.orderByDesc("update_time");
		IPage<Project> page = new PageModel<>(pageNo,pageSize);
		return projectMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个平台项目
	 * @param id
	 * @return
	 */
	@Override
	public Project getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个平台项目
	 * @param project
	 * @return
	 */
	@Override
	public Project add(Project project)  {
		
		projectMapper.insert(project);
		return project;
	}

	/**
	 * 更新单个平台项目
	 * @param project
	 * @return
	 * @
	 */
	@Override
	public int update(Project project)  {
		
		return projectMapper.updateById(project);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] projectIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(projectIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
